package com.bao.interkont.controller;

import com.bao.interkont.pojo.Article;
import com.bao.interkont.pojo.Result;
import com.bao.interkont.server.ArticleServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author bao*
 * @version 1.0
 */
@RestController
public class ArticleController {
    @Autowired
    private ArticleServer articleServer;

    @GetMapping("/articles")
    public Result getArticles() {
        return Result.success(articleServer.getArticles());
    }

    @GetMapping("/articles/{articleId}")
    public Result getArticleByArticleId(@PathVariable Integer articleId) {
        return Result.success(articleServer.getArticleByArticleId(articleId));
    }

    @PostMapping("/articles")
    public Result publishArticle(@RequestBody Article article) {
        articleServer.publishArticle(article);
        return Result.success();
    }
}
